// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        isChoosed : {
            default : false,
            visible : false,
        }

        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
		//this.node.on(cc.Node.EventType.MOUSE_DOWN,  this.onMouseDown, this);
        this.node.on('touchstart', this.onMouseDown, this);
    },

	onMouseDown(event) {
        console.log(this.id);

        if(!this.isChoosed) {
            this.node.setPosition(this.node.x, this.node.y + 20);
            this.game.chooseCard(this.id);
        }
        else {
            this.node.setPosition(this.node.x, this.node.y - 20);
            this.game.cancelChooseCard(this.id);
        }
        this.isChoosed = !this.isChoosed;
        console.log(this.value);
		
	},

	onDestroy() {
		//this.node.off(cc.Node.EventType.MOUSE_DOWN,  this.onMouseDown, this);
        this.node.off('touchstart', this.onMouseDown, this);

	},

    setId(id) {
        this.id = id;
    },

    notChoose() {
        if(this.isChoosed) {
            this.node.setPosition(this.node.x, this.node.y - 20);
            this.game.cancelChooseCard(this.id);
            this.isChoosed = !this.isChoosed;
        }
    },

    choose() {
        if(!this.isChoosed) {
            this.node.setPosition(this.node.x, this.node.y + 20);
            this.isChoosed = !this.isChoosed;
        }
    },

    notChoose2() {
        if (this.isChoosed) {
            this.node.setPosition(this.node.x, this.node.y - 20);
            this.isChoosed = !this.isChoosed;
        }
    },

    getValue : function() {
        return this.value;
    }
    // update (dt) {},
});
